/*e.preventDefault();//阻止元素发生默认的行为(例如,当点击提交按钮时阻止对表单的提交*/


var urlHeader = localStorage.getItem('host');
//var urlHeader = "http://10.156.0.209:8088/ks_manager/manager/";
var insertProductPropertyContent = urlHeader + "manager/insertLoanMethodDefineNew.do";
var insertProductFee = urlHeader + "manager/insertProductFeeDefineNew.do";
var queryLoanDefine= urlHeader +"manager/queryLoanDefineByProductId.do";
var queryFeeDefine= urlHeader +"manager/queryFeeDefineByProductId.do";
var delLoan = urlHeader + "manager/delLoanDefineInfo.do";
var delFee = urlHeader + "manager/delFeeDefineInfo.do";




// function getAurlparam(name) {
//     return top.getAurlparam(name);
// }

function checkLoanMehtodID( c , ID ){
    var loan_mehtod_id = $(c).attr('loan_mehtod_id');
    if(!loan_mehtod_id || loan_mehtod_id == 'undefined'){
        $(c).attr('loan_mehtod_id' , ID);//服务端新增后，替换这个值
    }
}

function checkFeeId( c, ID ){
    var fee_id = $(c).attr( 'fee_id' );
    if( !fee_id ){
        $(c).attr( 'fee_id' , ID );//服务端新增后，替换这个值
    }
}

function insertPF(data){
    data.productId = getAurlparam('productId')
    $.ajax({
        url:insertProductFee,
        type:'POST',
        crossDomain: true,
        xhrFields:{
            withCredentials: true
        },
        data:{
            frontData:JSON.stringify(data)
        },
        success:function(data){
            if (data == 'noLogin') {
                location.href = "login/login.html"
            }
            if (data == 'noRole') {
                Constant.fn.Message('F',data.msg);
                //$("#loading").hide();
                return;
            }
            $.ajax({
                url:queryFeeDefine,
                type:'POST',
                crossDomain: true,
                xhrFields:{
                    withCredentials: true
                },
                data:{
                    product_id:getAurlparam('productId')
                },
                success:function(data){
                    data = JSON.parse(data)
                    if(data.type == 1){
                        var html = "<span><label class=\"checkbox inline\" style=\"height: auto; padding:5px 0 0 20px; box-shadow: none\"><input type=\"checkbox\" name=\"leipiNewField\" title=\"复选框\" value=\"选项1\" orginline=\"inline\" style=\"width: 15px;\">利率</label><label class=\"text slabel isDisabled\" style=\"display: block\"><input type=\"text\" class=\"ng-pristine ng-untouched ng-valid ng-empty\">分</label></span><i style=\"display: none\"><label class=\"checkbox inline\" style=\"height: auto; padding:5px 0 0 20px; box-shadow: none\"><input type=\"checkbox\" name=\"leipiNewField\" title=\"复选框\" value=\"选项1\" class=\"leipiplugins\" leipiplugins=\"checkbox\" orginline=\"inline\" style=\"width: 15px\"></label><label class=\"text slabel isDisabled\" style=\"display: block\"><input type=\"text\"></label></i>\n";
                        if(data.content){
                            //$("#loanwayadd").toggle();
                            $.each(data.content,function(i,e){
                                html += '<i><label class="checkbox inline"  id="'+e.id+'" style="height: auto; padding:5px 0 0 20px; box-shadow: none"><input type="checkbox"  name="leipiNewField" title="复选框" orginline="inline" style="width: 15px;">'+e.name+'</label><label class="text slabel isDisabled" style="display: block"><input type="text" key="'+e.english_name+'" class="ng-pristine ng-untouched ng-valid ng-empty">'+e.type+'</label></i>';
                            })
                        }
                        $("#count").html(html);
                    }
                }
            })
        }
    })
}


function insertContent(data){
    data.productId = getAurlparam('productId')
    $.ajax({
        url:insertProductPropertyContent,
        type:'POST',
        crossDomain: true,
        xhrFields:{
            withCredentials: true
        },
        data:{
            frontData:JSON.stringify(data)
        },
        success:function(data){
            if (data == 'noLogin') {
                location.href = "login/login.html"
            }
            if (data == 'noRole') {
                Constant.fn.Message('F',data.msg);
                //$("#loading").hide();
                return;
            }
            $.ajax({
                url:queryLoanDefine,
                type:'POST',
                crossDomain: true,
                xhrFields:{
                    withCredentials: true
                },
                data:{
                    product_id:getAurlparam('productId')
                },
                success:function(data){
                    data = JSON.parse(data)
                    if(data.type ==1){
                        var html = "<!-- Multiple Checkboxes -->\n";
                        if(data.content.length > 0){
                            $("#loanwayadd").hide();
                            $.each(data.content,function(i,e){
                                html += '<label class="radio inline">\n<input type="radio" leipiplugins="radio"  name="leipiNewField" title="单选框" value="'+e.name+'" orginline="inline" key="'+e.english_name+'" loan_mehtod_id="'+e.id+'" class="leipiplugins" style="width: 15px">'+e.name+'\n</label>';
                            })
                            $("#loanway").html(html);
                        }
                        else{
                            $("#loanwayadd").show();
                            $("#loanway").html("<label style=\"display:none\" class=\"radio inline\"><input type=\"radio\" leipiplugins=\"radio\" name=\"leipiNewField\"  title=\"单选框\"  orginline=\"inline\" class=\"leipiplugins\" style=\"width: 15px\"></label>\n");
                        }

                    }
                }
            })
        }
    })
}
//修改component控件的span
LPB.changeSpan = function( active_component , attr_name, attr_val ) {
    if( attr_name ==  'orgspan'){
        var old = active_component.attr("orgspan");
        active_component.attr("orgspan",attr_val);
        active_component.removeClass( 'span' + old );
        active_component.addClass( 'span' + attr_val  );
    }
}


/* 文本框控件 text
acc  是 class="component" 的DIV
e 是 class="leipiplugins" 的控件
*/
LPB.plugins['text'] = function (active_component,leipiplugins) {
    var plugins = 'text',popover = $(".popover");
    //右弹form  初始化值
    $(popover).find("#orgname").val($(leipiplugins).attr("title"));
    $(popover).find("#orgvalue").val($(leipiplugins).val());
    $(popover).find("#orgspan").val( active_component.attr("orgspan"));

    //右弹form  取消控件
    $(popover).delegate(".btn-warning", "click", function(e){
        active_component.popover("hide");
    });
    //右弹form  确定控件
    $(popover).delegate(".btn-info", "click", function(e){

        var inputs = $(popover).find("input");
        if($(popover).find("textarea").length>0)
        {
            inputs.push($(popover).find("textarea")[0]);
        }
        $.each(inputs, function(i,e){
            var attr_name = $(e).attr("id");//属性名称
            var attr_val = $(e).val();
            LPB.changeSpan( active_component , attr_name , attr_val );
            switch(attr_name)
            {
                //要break
                case 'orgvalue': {
                    //$(leipiplugins).val(attr_val);
                    $(leipiplugins).attr("value", attr_val);
                    break;
                }
                //没有break
                case 'orgname':{
                    $(leipiplugins).attr("title",attr_val);
                    active_component.find(".leipiplugins-orgname").text(attr_val);
                    break;
                }
                default:
                    $(leipiplugins).attr(attr_name, attr_val);
            }
            active_component.popover("hide");
            LPB.genSource();//重置源代码

        });
        $(leipiplugins).show();
        active_component.find('button').hide();
    });
    //删除按钮
}
/* 多行文本框控件 textarea
acc  是 class="component" 的DIV
e 是 class="leipiplugins" 的控件
*/
LPB.plugins['textarea'] = function (active_component,leipiplugins) {
    var plugins = 'textarea',popover = $(".popover");
    //右弹form  初始化值
    $(popover).find("#orgname").val($(leipiplugins).attr("title"));
    $(popover).find("#orgvalue").val($(leipiplugins).val());
    $(popover).find("#orgspan").val( active_component.attr("orgspan") );

    //右弹form  取消控件
    $(popover).delegate(".btn-warning", "click", function(e){

        active_component.popover("hide");
    });
    //右弹form  确定控件
    $(popover).delegate(".btn-info", "click", function(e){

        var inputs = $(popover).find("input");
        if($(popover).find("textarea").length>0)
        {
            inputs.push($(popover).find("textarea")[0]);
        }
        $.each(inputs, function(i,e){
            var attr_name = $(e).attr("id");//属性名称
            var attr_val = $(e).val();
            LPB.changeSpan( active_component , attr_name , attr_val );
            switch(attr_name)
            {
                //要break
                case 'orgvalue':
                    //$(leipiplugins).val(attr_val);
                    $(leipiplugins).text(attr_val);
                    break;
                //没有break
                case 'orgname':
                    $(leipiplugins).attr("title",attr_val);
                    active_component.find(".leipiplugins-orgname").text(attr_val);
                default:
                    $(leipiplugins).attr(attr_name, attr_val);
            }
            active_component.popover("hide");
            LPB.genSource();//重置源代码
        });
    });
}
/* 下拉框控件 select
acc  是 class="component" 的DIV
e 是 class="leipiplugins" 的控件
*/
LPB.plugins['select'] = function (active_component,leipiplugins) {
    var plugins = 'select',popover = $(".popover");
    var define_id = active_component.attr('define_id');
    //var key = $(leipiplugins).data('key');

    var val = $.map($(leipiplugins).find("option"), function(e,i){return $(e).text()});
    val = val.join("\r");

    /*if(!leipiplugins){
        leipiplugins = "<select></select>"
    }*/
    //右弹form  初始化值
    $(popover).find("#orgname").val($(leipiplugins).attr("title"));
    $(popover).find("#orgspan").val( active_component.attr("orgspan"));


    $(popover).find("#orgvalue").text(val);
    //右弹form  取消控件
    $(popover).delegate(".btn-warning", "click", function(e){
        active_component.popover("hide");
    });
    //右弹form  确定控件
    $(popover).delegate(".btn-info", "click", function(e){

        var inputs = $(popover).find("input");
        if($(popover).find("textarea").length>0)
        {
            inputs.push($(popover).find("textarea")[0]);
        }
        $.each(inputs, function(i,e){
            var attr_name = $(e).attr("id");//属性名称
            var attr_val = $(e).val();
            LPB.changeSpan( active_component , attr_name , attr_val );
            switch(attr_name)
            {
                //要break
                case 'orgvalue':
                    var options = attr_val.split("\n");
                    $(leipiplugins).html("");
                    $.each(options, function(i,e){
                        $(leipiplugins).append("\n      ");
                        $(leipiplugins).append($("<option>").text(e));
                    });
                    //$(leipiplugins).text(attr_val);
                    break;

                case 'orgname':
                    $(leipiplugins).attr("title",attr_val);
                    active_component.find(".leipiplugins-orgname").text(attr_val);
                    break;
                default:
                    $(leipiplugins).attr(attr_name, attr_val);
            }
            active_component.popover("hide");
            LPB.genSource();//重置源代码
        });

        //显示新增的值
        $(leipiplugins).show();

        //隐藏按钮
        active_component.find('button').hide();





        var data =new Object();

        var obj = new Array();

        var va = $(leipiplugins).find("option");

        $.each(va,function(i,e){
            checkContentID($(e),'data_'+ define_id + i +'c');
            obj.push({
                content:$(e).text(),
                content_id:$(e).attr('content_id')
            })
        })

        //data[key] = value;
        data.propertyDefId = active_component.attr('define_id');
        //data.define_type = 'select';
        data.propertyContents = obj;
        insertContent(data);
    });
}

/* 复选控件 checkbox
acc  是 class="component" 的DIV
e 是 class="leipiplugins" 的控件
*/
LPB.plugins['checkbox'] = function (active_component,leipiplugins) {
    var plugins = 'checkbox',popover = $(".popover");
    //右弹form  初始化值
    $(popover).find("#orgname").val($(leipiplugins).attr("title"));
    $(popover).find("#orgspan").val(active_component.attr("orgspan"));
    var val = $.map($(leipiplugins), function(e,i){return $(e).val().trim()});
    val = val.join("\r");
    $(popover).find("#orgvalue").text(val);
    //右弹form  取消控件
    $(popover).delegate(".btn-warning", "click", function(e){

        active_component.popover("hide");
    });
    //右弹form  确定控件
    $(popover).delegate(".btn-info", "click", function(e){

        var inputs = $(popover).find("input");
        if($(popover).find("textarea").length>0)
        {
            inputs.push($(popover).find("textarea")[0]);
        }
        $.each(inputs, function(i,e){
            var attr_name = $(e).attr("id");//属性名称
            var attr_val = $(e).val();
            LPB.changeSpan( active_component , attr_name , attr_val );
            switch(attr_name)
            {
                //要break
                case 'orgvalue':
                    var checkboxes = attr_val.split("\n");
                    var html = "<!-- Multiple Checkboxes -->\n";
                    $.each(checkboxes, function(i,e){
                        if(e.length > 0){
                            var vName = $(leipiplugins).eq(i).attr("name"),vTitle = $(leipiplugins).eq(i).attr("title"),orginline = $(leipiplugins).eq(i).attr("orginline");
                            if(!vName) vName = ''; if(!vTitle) vTitle = ''; if(!orginline) orginline = 'inline';
                            html += '<label class="checkbox '+orginline+'">\n<input type="checkbox" name="'+vName+'" title="'+vTitle+'" value="'+e+'" orginline="'+orginline+'" class="leipiplugins" style="width: 15px"  >'+e+'\n</label>';
                        }
                        $(active_component).find(".leipiplugins-orgvalue").html(html);
                    });
                    break;

                case 'orgname':
                    $(leipiplugins).attr("title",attr_val);
                    active_component.find(".leipiplugins-orgname").text(attr_val);
                    break;
                default:
                    $(leipiplugins).attr(attr_name, attr_val);
            }
            active_component.popover("hide");
            LPB.genSource();//重置源代码
        });
        $(leipiplugins).show();
        active_component.find('button').hide();
    });
}

/* 复选控件 radio
acc  是 class="component" 的DIV
e 是 class="leipiplugins" 的控件
*/
LPB.plugins['radio'] = function (active_component,leipiplugins) {
    var plugins = 'radio', popover = $(".popover");
    var defined_id = active_component.attr("define_id")
    //右弹form  初始化值

    var val = $.map($(leipiplugins), function (e, i) {
        if($(e).val()&& $(e).val()!= 'on'){
            return $(e).val().trim()
        }
    });
    //val = val.join("\r");

    var key = $.map($(leipiplugins), function (e, i) {
        if($(e).attr('key')){
            return $(e).attr('key').trim()
        }
    });

    var id = $.map($(leipiplugins), function (e, i) {
        if($(e).attr('loan_mehtod_id')){
            return $(e).attr('loan_mehtod_id').trim()
        }
    });

    //key = key.join("\r");
    var html = ''

    $.each(val,function(i,e){
        html += '<div class="group"><input placeholder="value" type="text" style="display: inline-block; width:80px; height: 20px; margin-right: 2px" id="orgvalue" value='+e+'><input placeholder="key" type="text" style="display: inline-block; width:80px;  height: 20px; margin-right: 2px" id="orgkey" value='+e+'><button style="height: 20px; margin-right: 0px; padding: 1px 6px" class="btn btn-danger" type="button">X</button></div>'
    })

    popover.find('.control-label').after(html);

    $.each(key,function(i,e){
        popover.find('.group input[id="orgkey"]').eq(i).val(e);
    })

    $.each(id,function(i,e){
        popover.find('.group').eq(i).attr('loan_mehtod_id',e);
    })

    //$(popover).find("#orgvalue").text(val);
    //$(popover).find("#orgkey").text(key);

    //右弹form  取消控件
    $(popover).delegate(".btn-warning", "click", function (e) {
        active_component.popover("hide");
    });
    //右弹form  确定控件
    $(popover).delegate(".btn-info", "click", function (e) {

        var inputs = $(popover).find('.group input[type="text"]');
        /*if($(popover).find("textarea").length>0)
        {
            inputs.push($(popover).find("textarea")[0]);
        }*/
        var html = "<!-- Multiple Checkboxes -->\n";
        $.each(inputs, function (i, e) {
            var attr_name = $(e).attr("id");//属性名称
            var loan_mehtod_id = $(e).parent('.group').attr('loan_mehtod_id');
            var attr_val = $(e).val();
            LPB.changeSpan(active_component, attr_name, attr_val);
            switch (attr_name) {
                //要break
                case 'orgvalue':
                    var checkboxes = attr_val.split("\n");
                    $.each(checkboxes, function (i, e) {
                        if (e.length > 0) {
                            var vName = $(leipiplugins).eq(i).attr("name"),
                                vTitle = $(leipiplugins).eq(i).attr("title"),
                                orginline = $(leipiplugins).eq(i).attr("orginline");
                            if (!vName) vName = 'leipiNewField';
                            if (!vTitle) vTitle = '单选框';
                            if (!orginline) orginline = 'inline';
                            html += '<label class="radio ' + orginline + '">\n<input type="radio" leipiplugins="radio"  name="' + vName + '" title="' + vTitle + '" loan_mehtod_id="'+loan_mehtod_id+'" value="' + e + '" orginline="' + orginline + '"  class="leipiplugins" style="width: 15px">' + e + '\n</label>';
                        }
                    });
                    $(active_component).find(".leipiplugins-orgvalue").html(html);
                    break;
                case 'orgkey':
                    var checkboxes = attr_val.split("\n");
                    //var html = "<!-- Multiple Checkboxes -->\n";
                    $.each(checkboxes, function (i, e) {
                        if (e.length > 0) {
                            $('label input[type="radio"]').eq(i).attr('key', e);
                        }
                        //$(active_component).find(".leipiplugins-orgvalue").html(html);
                    });
                    break;
                case 'orgname':
                    $(leipiplugins).attr("title", attr_val);
                    active_component.find(".leipiplugins-orgname").text(attr_val);
                    break;

                default:
                    $(leipiplugins).attr(attr_name, attr_val);
            }
            active_component.popover("hide");
            LPB.genSource();//重置源代码
        });
        active_component.find('button').hide();

        var data = new Object();

        var obj = new Array();

        var va = active_component.find("input[type='radio']");
        $.each(va, function (i, e) {
            checkLoanMehtodID($(e), 'data_' + defined_id + i + 'c');
            obj.push({
                name: $(e).val(),
                english_name: $(e).val(),
                value: $(e).val(),
                loan_mehtod_id: $(e).attr('loan_mehtod_id')
            })
        })

        //data[key] = value;
        data.loanMehtodDefines = obj;
        data.propertyDefId = active_component.attr('loan_mehtod_id');
        insertContent(data);
    });

    $(popover).delegate(".btn-danger", "click", function (e) {
        var e = $(this).parent('div')
        e.remove();
        var ids = $(e).attr('loan_mehtod_id')
        if(ids){
            $.ajax({
                url:delLoan,
                type:"POST",
                data:{
                    ids:ids
                },
                crossDomain: true,
                xhrFields:{
                    withCredentials: true
                },
                success:function(data){
                    data = JSON.parse(data);
                    if(data.type == 1){

                    }else{
                        Constant.fn.Message("F",data.msg)
                    }
                }
            })
        }
    })

    $(popover).delegate(".btn-default", "click", function (e) {
        $(this).parent('div').remove();
    })

    $(popover).delegate(".btn-success", "click", function (e) {
        $(this).parent('label').siblings('.group:last').after("<div class=\"group\"><input placeholder=\"value\" type=\"text\" style='display: inline-block; width:80px; height: 20px; margin-right: 2px' id='orgvalue'/><input placeholder=\"key\" type=\"text\" style='display: inline-block; width:80px;  height: 20px; margin-right: 2px' id='orgkey' /><button style=\"height: 20px; margin-right: 0px; padding: 1px 6px\" class='btn btn-danger' type='button'>X</button></div>")
    })
}

/*复选框和文本框结合组件*/

LPB.plugins['charging'] = function (active_component,leipiplugins) {
    var plugins = 'select', popover = $(".popover");

    //var key = $(leipiplugins).data('key');

    //右弹form  初始化值

    var val = $.map($(leipiplugins).find('i').find(".checkbox"), function (e, i) {
        if ($(e).text()) {
            return $(e).text().trim()
        }
    });

    var id = $.map($(leipiplugins).find('i').find(".checkbox"), function (e, i) {
        if ($(e).attr('id')) {
            return $(e).attr('id').trim()
        }
    });

    //val = val.join("\r");

    var unit = $.map($(leipiplugins).find('i').find(".text"), function (e, i) {
        if ($(e).text()) {
            return $(e).text().trim()
        }
    });

    var key = $.map($(leipiplugins).find('i').find(".text input[type='text']"), function (e, i) {
        if ($(e).attr('key')) {
            return $(e).attr('key').trim()
        }
    });


    //key = key.join("\r");
    var html = ''

    $.each(val, function (i, e) {
        html += '<div class="group"><input placeholder="value" type="text" style="display: inline-block; width:53px; height: 20px; margin-right: 2px" id="orgcbvalue" value=' + val + ' ><input placeholder="value" type="text" style="display: inline-block; width:53px; height: 20px; margin-right: 2px" id="orgtxtvalue"/><input placeholder="key" type="text" style="display: inline-block; width:53px;  height: 20px; margin-right: 2px" id="orgkey" /><button style="height: 20px; margin-right: 0px;" class="btn btn-danger" type="button">X</button></div>'
    })

    popover.find('.control-label').after(html);

    $.each(key, function (i, e) {
        popover.find('.group input[id="orgkey"]').eq(i).val(e);
    })

    $.each(unit, function (i, e) {
        popover.find('.group input[id="orgtxtvalue"]').eq(i).val(e);
    })


    $.each(id, function (i, e) {
        popover.find('.group').eq(i).attr('id', e);
    })

    /*var cbval = $.map($(leipiplugins).find('i').find(".checkbox"), function(e,i){return $(e).text()});
    cbval = cbval.join("\r");

    var keyval = $.map($(leipiplugins).find('i').find(".checkbox"), function+(e,i){return $(e).text()});
    keyval = keyval.join("\r");

    var textval = $.map($(leipiplugins).find('i').find(".text"), function(e,i){return $(e).text()});
    textval = textval.join("\r");*/
    /*if(!leipiplugins){
        leipiplugins = "<select></select>"
    }*/


    //右弹form  初始化值


    //右弹form  取消控件
    $(popover).delegate(".btn-warning", "click", function (e) {
        active_component.popover("hide");
    });
    //右弹form  确定控件
    $(popover).delegate(".btn-info", "click", function (e) {

        // /两个textarea
        var inputs = $(popover).find('.group input[type="text"]');

        /*if($(popover).find("textarea").length>0)
        {
            $.each($)
            inputs.push($(popover).find("textarea")[0]);
        }*/

        //遍历textarea，生成控件
        $.each(inputs, function (i, e) {
            var attr_name = $(e).attr("id");//属性名称
            var attr_val = $(e).val();
            LPB.changeSpan(active_component, attr_name, attr_val);
            switch (attr_name) {
                //要break
                //如果是左边的textarea，生成checkbox

                case 'orgcbvalue':
                    var options = attr_val.split("\n");
                    $(leipiplugins).html("<span><label class=\"checkbox inline\" style=\"height: auto; padding:5px 0 0 20px; box-shadow: none\"><input type=\"checkbox\" name=\"leipiNewField\" title=\"复选框\" value=\"选项1\" orginline=\"inline\" style=\"width: 15px;\">利率</label><label class=\"text slabel isDisabled\" style=\"display: block\"><input type=\"text\" class=\"ng-pristine ng-untouched ng-valid ng-empty\">分</label></span>");
                    $.each(options, function (i, e) {
                        $(leipiplugins).append("<i></i>");
                        $(leipiplugins).find('i').eq(i).append($("<label class=\"checkbox inline\" style=\"height: auto; padding:5px 0 0 20px; box-shadow: none\"><input type=\"checkbox\" name=\"leipiNewField\" title=\"复选框\" value=\"选项1\" class=\"leipiplugins\" leipiplugins=\"checkbox\" orginline=\"inline\" style=\"width: 15px\">" + e + "</label>"));
                    });
                    //$(leipiplugins).text(attr_val);
                    break;
                case 'orgkey':
                    var options = attr_val.split("\n");
                    $(leipiplugins).attr("title", attr_val);
                    $.each(options, function (i, e) {
                        $(leipiplugins).find('i input[type="text"]').eq(i).attr('key', e);
                    });
                    break;
                //如果是右边的textarea，生成
                case 'orgtxtvalue':
                    var options = attr_val.split("\n");
                    $.each(options, function (i, e) {
                        $(leipiplugins).find('i').eq(i).append($("<label class=\"text slabel isDisabled\" style=\"display: block\"><input type=\"text\" class=\"leipiplugins\" leipiplugins=\"checkbox\">" + e + "</label>"));
                    });
                    break;

                default:
                    $(leipiplugins).attr(attr_name, attr_val);
            }
            active_component.popover("hide");
            LPB.genSource();//重置源代码
        });

        //显示新增的值
        $(leipiplugins).show();

        //隐藏按钮
        active_component.find('button').hide();

        //获取content和content_id值

        var data = new Object();

        var obj = new Array();

        $.each(active_component.find('i'), function (i, e) {
            checkFeeId($(e), 'data_' + i + '1' + 'c');
            var fee_id = $(e).attr('fee_id')
            $.each($(e), function (ii, ee) {
                obj.push({
                    name: $(ee).find("label").eq(0).text(),
                    type: $(ee).find("label").eq(1).text(),
                    english_name: $(ee).find("label").eq(1).find('input[type="text"]').attr('key'),
                    fee_id: fee_id,
                })
            })
        })

        data.productFeeDefines = obj;
        insertPF(data)
    });

    $(popover).delegate(".btn-danger", "click", function (e) {
        var e = $(this).parent('div')
        e.remove();
        var ids = $(e).attr('id')
        if (ids) {
            $.ajax({
                url: delFee,
                type: "POST",
                data: {
                    ids: ids
                },
                crossDomain: true,
                xhrFields: {
                    withCredentials: true
                },
                success: function (data) {
                    data = JSON.parse(data);
                    if (data.type == 1) {

                    } else {
                        Constant.fn.Message("F",data.msg)
                    }
                }
            })
        }
    })

    $(popover).delegate(".btn-success", "click", function (e) {
        $(this).parent('label').siblings('.group:last').after("<div class=\"group\"><input placeholder=\"value\" type=\"text\" style='display: inline-block; width:53px; height: 20px; margin-right: 2px' id='orgcbvalue'/><input placeholder=\"value\" type=\"text\" style='display: inline-block; width:53px; height: 20px; margin-right: 2px' id='orgtxtvalue'/><input placeholder=\"key\" type=\"text\" style='display: inline-block; width:53px;  height: 20px; margin-right: 2px' id='orgkey' /><button style=\"height: 20px; margin-right: 0px;\" class='btn btn-danger' type='button'>X</button></div>")
    })
}
/* 上传控件 uploadfile
acc  是 class="component" 的DIV
e 是 class="leipiplugins" 的控件
*/
LPB.plugins['uploadfile'] = function (active_component,leipiplugins) {
    var plugins = 'uploadfile',popover = $(".popover");
    //右弹form  初始化值
    $(popover).find("#orgname").val($(leipiplugins).attr("title"));
    $(popover).find("#orgspan").val( active_component.attr("orgspan") );
    //右弹form  取消控件
    $(popover).delegate(".btn-warning", "click", function(e){

        active_component.popover("hide");
    });
    //右弹form  确定控件
    $(popover).delegate(".btn-info", "click", function(e){

        var inputs = $(popover).find("input");
        if($(popover).find("textarea").length>0)
        {
            inputs.push($(popover).find("textarea")[0]);
        }
        $.each(inputs, function(i,e){
            var attr_name = $(e).attr("id");//属性名称
            var attr_val = $(e).val();
            LPB.changeSpan( active_component , attr_name , attr_val );
            switch(attr_name)
            {
                case 'orgname':
                    $(leipiplugins).attr("title",attr_val);
                    active_component.find(".leipiplugins-orgname").text(attr_val);
                    break;
                default:
                    $(leipiplugins).attr(attr_name, attr_val);
            }
            active_component.popover("hide");
            LPB.genSource();//重置源代码
        });
    });
}